<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>分类管理</title>
    <style>
        body {
            font-family: "Arial", sans-serif;
            margin: 0;
            padding: 0;
            background: url('background.jpg') no-repeat center center fixed;
            background-size: cover;
            color: #fff;
        }

        .container {
            padding: 20px;
            max-width: 1200px;
            margin: auto;
            background: rgba(0, 0, 0, 0.7);
            border-radius: 10px;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2);
        }

        h1 {
            text-align: center;
            color: #ff6f61;
            margin-bottom: 20px;
        }

        h3 a {
            color: #ff6f61;
            text-decoration: none;
            font-size: 16px;
        }

        h3 a:hover {
            color: #ff5a4d;
        }

        form {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }

        form input[type="text"] {
            width: 70%;
            padding: 10px;
            border: 1px solid #ced4da;
            border-radius: 5px;
            font-size: 14px;
        }

        form button,
        form a {
            padding: 10px 20px;
            background-color: #ff6f61;
            color: #fff;
            border: none;
            border-radius: 5px;
            font-size: 14px;
            text-decoration: none;
            cursor: pointer;
            text-align: center;
        }

        form button:hover,
        form a:hover {
            background-color: #ff5a4d;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            background: rgba(255, 255, 255, 0.9);
            border-radius: 5px;
            overflow: hidden;
            margin-bottom: 20px;
        }

        th, td {
            padding: 15px;
            text-align: center;
            border: 1px solid rgba(0, 0, 0, 0.1);
            color: #212529;
        }

        th {
            background-color: #ff6f61;
            color: white;
        }

        td a {
            color: #ff6f61;
            text-decoration: none;
        }

        td a:hover {
            color: #ff5a4d;
        }

        .pagination {
            text-align: center;
            margin-top: 20px;
        }

        .pagination a {
            margin: 0 5px;
            padding: 5px 10px;
            text-decoration: none;
            color: #495057;
            border-radius: 3px;
            background: #fff;
        }

        .pagination a.active {
            font-weight: bold;
            color: #ff6f61;
            background: #ffebe8;
        }

        .pagination a:hover {
            color: #ff5a4d;
        }
    </style>
</head>
<body>
<div class="container">
    <h1>分类管理</h1>
    <h3><a href="admin.jsp">返回</a></h3>
    <form method="get" action="CategoryServlet">
        <input type="text" name="search" placeholder="搜索分类" value="${param.search}"/>
        <button type="submit">搜索</button>
        <a href="addcategory.jsp">新增分类</a>
    </form>
    <table>
        <thead>
        <tr>
            <th>ID</th>
            <th>分类名称</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach var="category" items="${categories}">
            <tr>
                <td>${category.id}</td>
                <td>${category.name}</td>
                <td>
                    <a href="editcategory.jsp?id=${category.id}">编辑</a> |
                    <a href="CategoryServlet?action=delete&id=${category.id}" onclick="return confirm('确认删除吗？');">删除</a>
                </td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <div class="pagination">
        <c:forEach var="page" begin="1" end="${totalPages}">
            <a href="CategoryServlet?page=${page}&search=${param.search}" class="${page == currentPage ? 'active' : ''}">${page}</a>
        </c:forEach>
    </div>
</div>
</body>
</html>
